package com.chixing.day01;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author Y2014188432
 */
public class Homework {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
//        定义两个变量，交换两个变量的值
//        int a = 10;
//        int b = 20;
        System.out.println("==== 第一题 =======");
        int a = 10;
        int b = 20;
        a += b;
        b = a - b;
        a = a - b;
        System.out.println(a+" "+b);
//        定义一个三位整数变量 x (999=>x>=100)，
//        将其分解出百位、十位、个位，并求出各位之和以及各位之积。
        System.out.println("==== 第二题 =======");
        System.out.println("请输入三位数");
        int sum = scanner.nextInt();
        int sumCopy = sum;
        int resultSum = 0;
        int resultRide = 1;
        for(int i = 0; i < 3;i++){
            int a1 = sum%10;
            resultSum += a1;
            resultRide *= a1;
            sum /= 10;
        }

        System.out.println(sumCopy+"的积是"+resultRide+"\n"+sumCopy+"的和是"+resultSum);
//        给定年份，判断是不是闰年（闰年的条件,能被400整除，或者能被4整除却不能被100整除）
//        int year = 2021;
        System.out.println("第三题");
        System.out.println("请输入所要判断的年份：");
        int year = scanner.nextInt();
        if(year%400 == 0 || (year%4 == 0 && year%100 !=0)){
            System.out.println("是闰年");
        }else{
            System.out.println("不是闰年");
        }
//        输出星号 1
        System.out.println("第四题");
        for (int i = 1; i < 6; i++) {
            for (int j = 0; j < i*2-1; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
//        输出星号 2
        System.out.println("第五题");
        for (int i = 0; i < 5; i++) {
            for (int j = 5; j > i ; j--) {
                System.out.print(" ");
            }
            for (int j = 0; j < 2*i+1; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
//        int[] score = {78,56,67,94,73,80,62,90,88,63};
        System.out.println("第六题");
        int[] score = {78,56,67,94,73,80,62,90,88,63};
        System.out.println("原数组为："+Arrays.toString(score));
        int length = score.length;
        for (int i = 0; i < length; i++) {
            for (int j = i+1; j < length; j++) {
                if(score[i] < score[j]){
                    int temp = score[i];
                    score[i] = score[j];
                    score[j] = temp;
                }
            }
        }
        System.out.println("数组为："+Arrays.toString(score));
    }
}
